********Table Q.1 - Mexico********

eststo clear

*Load data and create differences
cd "$reploc/data/created_data"
use mex_full, clear

sort pid_link mxfls
drop if mxfls==.
keep if panel==1

keep rbuc* mxfls pid_link inflation imp_age panel birthyr grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? birthstate yearprov

reshape wide rbuc*  inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co?, i(pid_link) j(mxfls)


local varlist1 rbuc rbuc_nga inflation grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co2 grbrprovSD_lam0co2 grbrprovAvg_lam0co3 grbrprovSD_lam0co3 


foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'3-`var'2
}

*Generate alternate clusters
*5-year by state of birth
egen fivyearclust=cut(birthyr), at(1915(5)2020) icodes
egen fivcoh_prov_clust=group(fivyearclust birthstate)

*10-year by state of birth
egen tenyearclust=cut(birthyr), at(1915(10)2020) icodes
egen tencoh_prov_clust=group(tenyearclust birthstate)

*15-year by state of birth
egen fifteenyearclust=cut(birthyr), at(1915(15)2020) icodes
egen fifteencoh_prov_clust=group(fifteenyearclust birthstate)

*Regressions
local x rbuc_nga
local rhsvari oldmexonly
local rhsvaruse _lam0co3dif
local usei grbr

drop if `x'dif==.

*Column 1
eststo:  reg `x'dif  `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'  inflationdif, vce(cluster fivcoh_prov_clust)

*Column 2
eststo:  reg `x'dif  `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'  inflationdif, vce(cluster tencoh_prov_clust)

*Column 3
eststo:  reg `x'dif  `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'  inflationdif, vce(cluster fifteencoh_prov_clust)

cd "$reploc/results"	
esttab using TableQ1_Mexico.tex, star(* 0.1 ** 0.05 *** 0.01) b(2) se(2) replace
